<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: header('新增策略')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-policy-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${policy.polId}"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectPolicyTree()" id="treeName" readonly="true"
                           th:value="${policy.polName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="polName" id="polName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderNum" required>
                <span class="help-block m-b-none">
                    <i class="fa fa-info-circle"></i> 数值越小越靠前</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分数：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="score">
                <span class="help-block m-b-none">
                    <i class="fa fa-info-circle"></i> 此处填写该项目的分数</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">策略状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:checked="${dict.isDefault == 'Y' ? true : false}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">需要输入：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <input type="radio" id="yes" name="input" value="0">
                    <label for="yes">是</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="no" name="input" checked value="1">
                    <label for="no">否</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">核定部门：</label>
            <div class="col-sm-8">
                <select id="depts" class="form-control select2-hidden-accessible" required>
                    <option value="">请选择该策略核定的部门</option>
                    <option th:each="dept:${depts}" th:value="${dept.deptId}" th:text="${dept.deptName}"
                            th:disabled="${dept.status == '1'}"></option>
                </select>
                <!--                <input class="form-control" type="text" onclick="selectDeptTree()" id="deptName" readonly="true" placeholder="请指定核定的部门">-->
            </div>
        </div>
        <h4 class="form-header h4">其他信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea name="remark" autocomplete="off" maxlength="500" class="form-control"
                                  rows="3"></textarea>
                        <span class="help-block m-b-none">
                            <i class="fa fa-info-circle"></i> 此处填写详细的规则明细</span>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "maintenance/policy";

    $("#form-policy-add").validate({
        onkeyup: false,
        rules: {
            orderNum: {
                digits: true
            },
            email: {
                email: true,
            },
            phoneNum: {
                isPhone: true,
            },
        },
        messages: {},
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var deptIds = $.form.selectSelects("depts");
            var data = $("#form-policy-add").serializeArray();
            data.push({"name": "deptId", "value": deptIds})
            $.operate.save(prefix + "/add", data);
            // console.log(data)
        }
    }

    /*策略管理-新增-选择父策略树*/
    function selectPolicyTree() {
        var options = {
            title: '策略选择',
            width: "380",
            url: prefix + "/selectPolicyTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
</script>
</body>
</html>
